home *** CD-ROM | disk | FTP | other *** search
/ Java for 3D & VRML Worlds / Java for 3d and VRML Worlds.iso / examples / chap04 / ProtoMan.java < prev    next >
Text File  |  1996-09-24  |  1KB  |  38 lines

  1. //
  2. // Walking man in prototype.
  3. //
  4.  
  5. import java.util.*;
  6. import vrml.*;
  7. import vrml.node.*;
  8. import vrml.field.*;
  9.  
  10. public class ProtoMan extends Script{
  11.     MFVec3f setPath;
  12.     float path[] = new float[3 * 2];    
  13.     Random randomNumGenerator = new Random();
  14.  
  15.     public void initialize(){
  16.         // get the reference of the event out 'setPath'.
  17.         setPath = (MFVec3f)getEventOut("setPath");
  18.         // initialize the path.
  19.         path[0] = 0.0f;         // start position
  20.         path[1] = 0.0f;
  21.         path[2] = 0.0f;
  22.         path[3] = 0.0f;         // end position
  23.         path[4] = 0.0f;
  24.         path[5] = 10.0f;
  25.     }
  26.  
  27.     public void processEvent(Event e){
  28.         if(e.getName().equals("cycleEnd") == true){
  29.             // decide how far the walking man goes in the next cycle.
  30.             // the distance is between 10.0 and 20.0
  31.             path[5] = 10.0f + randomNumGenerator.nextFloat() * 10.0f;
  32.             // send the event.
  33.             setPath.setValue(3 * 2, path);
  34.         }
  35.     }
  36. }
  37.  
  38.